﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace chap12 {
    class Program {
        private static void Main(string[] args) {
            Console.WriteLine("chap 12");

            QueryOverStrings();
            Console.WriteLine("");

            QueryOverInts();
            Console.WriteLine("");

            Console.ReadLine();
        }

        public static void QueryOverStrings() {
            // Assume we have an array of strings.
            String[] currentVideoGames = {
                                             "Morrowind", "Uncharted 2", "Fallout 3",
                                             "Daxter", "System Shock 2"
                                         };

            // Build a query expression to find the items in the array
            // that have an embedded space.
            IEnumerable<String> subset = from g in currentVideoGames
                                         where g.Contains(" ")
                                         orderby g
                                         select g;

            // Print out the results.
            foreach (var i in subset) {
                Console.WriteLine("item: " + i);
            }
            ReflectOverQueryResults(subset);
        }

        private static void QueryOverInts() {
            int[] numbers = {9, 20, 30, 40, 1, 2, 3, 8};
            // Print only items less than 10.
           var subset = from i in numbers
                                      where i < 10
                                      orderby i
                                      select i;
            foreach (var i in subset) {
                Console.WriteLine("Item: {0}", i);
            }
            ReflectOverQueryResults(subset);
        }

        private static void ReflectOverQueryResults(object resultSet) {
            Console.WriteLine("***** Info about your query *****");
            Console.WriteLine("resultSet is of type: {0}", resultSet.GetType().Name);
            Console.WriteLine("resultSet location: {0}",
                              resultSet.GetType().Assembly.GetName().Name);
        }
    }
}